package com.flyqiu.flow.core.handler;

import com.flyqiu.flow.api.context.ProcInstContext;
import com.flyqiu.flow.api.element.FlyQiuFlowElementManage;

import com.flyqiu.flow.bpmn.element.ParallelGateway;
import com.flyqiu.flow.bpmn.element.SequenceFlow;
import com.flyqiu.flow.model.entity.ru.ProcRuActivity;

import java.util.List;

public class ParallelGatewayHandler extends BaseComplexGatewayHandler<ParallelGateway> {

    @Override
    protected void startNextActivity(ProcInstContext procContext, ProcRuActivity currentRuActivity) {
        List<SequenceFlow> outgoingFlows = currentElement.getOutgoingFlows();
        if (outgoingFlows.isEmpty()) {
            throw new RuntimeException("not find next SequenceFlow");
        }
        FlyQiuFlowElementManage procElementConfig = procContext.getGlobalContext().getFlowElementManage();
        for (SequenceFlow flow : outgoingFlows) {
            procElementConfig.createStartInst(flow.getElementType()).start(procContext, flow.getDefKey());
        }
    }
}
